package com.yb.personelmanagement.service.init;


import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.yb.personelmanagement.domain.System.DataPermission;
import com.yb.personelmanagement.domain.System.DataRole;
import com.yb.personelmanagement.domain.System.Permission;
import com.yb.personelmanagement.domain.System.Role;
import com.yb.personelmanagement.domain.System.User;




/**
 * 系统权限数据初始化
 * 
 * @author Shinelon
 *
 */
public class JurisdictionInit {
	/**
	 * 数据权限列表
	 * 
	 * @return
	 */
	public static List<DataPermission> dataPermissionListInit() {
		List<DataPermission> dataPermissionList = new ArrayList<DataPermission>();
		
		dataPermissionList.add(new DataPermission(1L, 0L, "10001", "省局全局人员权限"));
		
		dataPermissionList.add(new DataPermission(2L, 1L, "10002", "省局财务规划处"));
		
		dataPermissionList.add(new DataPermission(3L, 1L, "10003", "省局人事机关处"));

		
		dataPermissionList.add(new DataPermission(4L, 0L, "20001", "衡水全局人员权限"));
		
		dataPermissionList.add(new DataPermission(5L, 4L, "20002", "衡水财务规划处"));
		
		dataPermissionList.add(new DataPermission(6L, 4L, "20003", "衡水人事机关处"));

		
		dataPermissionList.add(new DataPermission(7L, 0L, "30001", "保定全局人员权限"));
			
		dataPermissionList.add(new DataPermission(8L, 4L, "30002", "保定财务规划处"));
			
		dataPermissionList.add(new DataPermission(9L, 4L, "30003", "保定人事机关处"));

		return dataPermissionList;
	}
	

	/**
	 * 系统角色列表
	 * 
	 * @return
	 */
	public static Set<DataRole> dataRoleListInit() {
		Set<DataRole> dataRoleList = new HashSet<>();

		List<DataPermission> permissionList = dataPermissionListInit();
		String dataRoleDesc="全部数据权限-";
		String ids="";
		
		for (Iterator iterator = permissionList.iterator(); iterator.hasNext();) {
			DataPermission dataPermission = (DataPermission) iterator.next();
			
			dataRoleDesc+=dataPermission.getDescription()+"_";
			ids+=dataPermission.getId()+",";
		}
		
		dataRoleList.add(new DataRole(1L, "全部数据权限", null, permissionList, ids, null, dataRoleDesc));
		
		
		dataRoleDesc="衡水数据权限_";
		ids="";
		List<DataPermission> hengshui=new ArrayList<DataPermission>();
		for (Iterator iterator = permissionList.iterator(); iterator.hasNext();) {
			DataPermission dataPermission = (DataPermission) iterator.next();
			
			if(dataPermission.getDescription().contains("衡水")) {
				
				dataRoleDesc+=dataPermission.getDescription()+"_";
				ids+=dataPermission.getId()+",";
				hengshui.add(dataPermission);
			}
			
			
		}
		dataRoleList.add(new DataRole(2L, "衡水权限", null, hengshui, ids, null, dataRoleDesc));
		
		
		
	  return dataRoleList;
		
		
		
	}

	
	
	/**
	 * 菜单权限列表
	 * 
	 * @return
	 */
	public static List<Permission> permissionListInit() {
		List<Permission> permissionList = new ArrayList<Permission>();
		
		permissionList.add(new Permission(1L, 0L, "/user", "用户管理菜单"));
		
		permissionList.add(new Permission(2L, 1L, "/user/addUser", "用户新增子菜单"));
		
		permissionList.add(new Permission(3L, 1L, "/user/queryUser", "用户查询子菜单"));

		
		permissionList.add(new Permission(4L, 0L, "/department", "部门管理菜单"));
		
		permissionList.add(new Permission(5L, 4L, "/department/addDepartment", "部门新增子菜单"));
		
		permissionList.add(new Permission(6L, 4L, "/department/queryDepartment", "部门查询"));


		return permissionList;
	}
	

	/**
	 * 系统角色列表
	 * 
	 * @return
	 */
	public static Set<Role> roleListInit() {
		Set<Role> dataRoleList = new HashSet<>();

		List<Permission> permissionList = permissionListInit();
		String dataRoleDesc="全部菜单角色-";
		String ids="";
		for (Iterator iterator = permissionList.iterator(); iterator.hasNext();) {
			Permission permission = (Permission) iterator.next();
			
			dataRoleDesc+=permission.getDescription()+"";
			ids=+permission.getId()+",";
		}
		
		dataRoleList.add(new Role(1L, "全部菜单角色", permissionList, ids, dataRoleDesc, 0, null));
	
	  return dataRoleList;
		
		
	}
	
	
	public  static List<User> userListInit(){
		List<User> userList=new ArrayList<>();
		

		
		userList.add(new  User(1L, "admin", "$2a$08$lDnHPz7eUkSi6ao14Twuau08mzhWrL4kyZGGU5xfiGALO/Vxd5DOi", 
				roleListInit(), dataRoleListInit(), null, "admin2222@126.com",new Timestamp(System.currentTimeMillis()), "超级管理员", "111111111111", "0311-11111111", null, null, null, 1));
		
		
		
		
		
		Set<DataRole> rs= dataRoleListInit();
		Set<DataRole> temp=new HashSet<>();
		for (Iterator iterator = rs.iterator(); iterator.hasNext();) {
			DataRole dataRole = (DataRole) iterator.next();
			if(dataRole.getRoleName().equals("衡水权限")) {
				temp.add(dataRole);
				
				userList.add(new  User(2L, "user", "$2a$08$lDnHPz7eUkSi6ao14Twuau08mzhWrL4kyZGGU5xfiGALO/Vxd5DOi", 
						roleListInit(), temp, null, "admin2222@126.com",new Timestamp(System.currentTimeMillis()), "衡水管理员", "111111111111", "0311-11111111", null, null, null, 1));

			}
			
		}
	
		return userList;
	}
	
	
}
